﻿
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="/lib/signalr/signalr.js"></script>
    <script src="/lib/jquery/dist/jquery.js"></script>
</head>
<body>
    <button id="btn2">getPerson</button><br />
    <script>
        document.getElementById("btn2").addEventListener("click", function () {

            connection.invoke("getPerson").catch(function (p) {
                alert("error");
            });

        });

      
    </script>

    <input type="text" id="userName" /><br />
    <input type="text" id="message" /><br />
    <button id="btn1">click</button>
    <script>
        
        'use strict'

        var connection = new signalR.HubConnectionBuilder().withUrl("/testHub").build();

        connection.on("onMessage", function (userName, msg) {
            alert("收到服务端信息:" + userName + "|" + msg);
        });

        connection.on("setPerson", function (p) {
             alert("收到服务端信息:" + p.id + "|" + p.name);
        });

      
        connection.start().catch(function (err) {
            return console.error(err.toString());
        });

        document.getElementById("btn1").addEventListener("click", function (event) {
            var user = document.getElementById("userName").value;
            var message = document.getElementById("message").value;
            connection.invoke("sendMessage", user, message).catch(function (err) {
                return console.error(err.toString());
            });
            event.preventDefault();
        });

      
    </script>
</body>
</html>